package com.jmm.neditor.controller.neditor;

import com.jmm.neditor.utils.template.HtmlTemplateUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * GenerateHtmlController class
 *
 * @author 蒋时华
 * @date 2018-5-9
 */
@RestController
@RequestMapping("/neditor/generate")
public class GenerateHtmlController {

    @PostMapping("/outPage")
    public String generateWeChatHtml(@RequestParam(required = false) String content, @RequestParam(required = false) Integer templateType){
        if(StringUtils.isEmpty(content) || templateType==null){
            return "error";
        }
//        if(content.startsWith(",")){
//            content = content.substring(1);
//        }
        try {
            String htmlName = HtmlTemplateUtil.weChatTemplateHtml(content, templateType);
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
        return "success";
    }
    @GetMapping("/outPage2/{pageName}")
    public ModelAndView per(@PathVariable String pageName){

        return new ModelAndView("editorPage/"+pageName);
    }
    @GetMapping("/outPage3")
    public ModelAndView per2(){

        return new ModelAndView("neditor/template/wechatTemplate");
    }

}
